<? include ("../init.php") ?>
<?
  if(!isset($_POST['aid'])){
    header("Location:index.php");
  }else{
    $aid = $_POST['aid'];
  }
  // ---------- UPLOADS Image ----------
  $handle = new Upload($_FILES['image']);
  
  if($handle->file_src_name != '')
  {
    if ($handle->uploaded)
    {
      $handle->image_resize = true;
      $handle->image_ratio_fill = true;
      $handle->image_x = 959;
      $handle->image_y = 111;
      
      $handle->Process(APPPATH.'/images/banner');
      
      if ($handle->processed)
      {
         $sql = "UPDATE hs_banner SET b_img='$handle->file_dst_name' WHERE b_id=$aid";
         if(!mysql_query($sql))
         {
              $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
              unlink(APPPATH."/images/banner/".$handle->file_dst_name);
         }
         else
         {
          if(isset($_POST['oldimg']) AND $_POST['oldimg']!=''){
            unlink(APPPATH."/images/banner/".$_POST['oldimg']);
          }
          $data_add[1] = "444444444444";
         }
      }
      else
      {
        $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
      }
      
      $handle->clean();
    }
    else
    {
        $data_add[1] = "Can\'t upload image file, please check again or contact the webmaster.";
    }
  }else{
    $data_add[1] = "ssssss";
  }
  
  $sql = 'UPDATE hs_banner SET b_url="'.$_POST['url'].'" WHERE b_id='.$aid;
  $xxx = mysql_query($sql);
  //var_dump($data_add);
  header("Location:index.php");
?>